<script language='javascript' type='text/javascript'>

	function troca(nome1, nome2)
	{

		var btn1 = document.getElementById(nome1);
		var btn2 = document.getElementById(nome2);

		btn1.style.display = '';
		btn2.style.display = 'none';
	}

</script>

<?php

	// Mensagem de Boas Vindas
	echo '	<div style="width:100%; margin:5px"> 
			<h2 style="width:100%; margin-top:10px"> Olá, '.$othAuth->user("name").'! </h2>
			<h4 style="margin-top:0px"> 
			Seja bem-vindo ao ONG Digital. Comece agora a gerenciar os dados de sua organização...
			</h4>
	        </div>';


	// Coluna da Esquerda
	echo '<div style="width:365px; display:block; float:left">';

		// Box de Estatísticas	
		if((isset($total_unidades)) && (isset($total_funcionarios)) && (isset($total_voluntarios)) && (isset($total_assistidos)))
		{
			// Box com Estatísticas
			echo $box->iniciaBloco("Entidade em números");
		
				echo "<div>";
		
				echo "<p><span> Unidades: </span><span>  ";		
				echo $total_unidades;		
				echo "</span></p>";
		
				echo "<p><span> Funcionários: </span><span>  ";
				echo $total_funcionarios;
				echo "</span></p>";
		
				echo "<p><span> Voluntários: </span><span>  ";
				echo $total_voluntarios;
				echo "</span></p>";
		
				echo "<p><span> Assitidos: </span><span>  ";
				echo $total_assistidos;
				echo "</span></p>";
		
		
				echo "</div>";
		
			echo $box->finalizaBloco();
		}
	
		// Box de Noticias	
		if(isset($noticias_geral))
		{
		echo $box->iniciaBloco("Notícias");
	
			// Corpo do Box de Notícias
			echo "<div>";
			$i = 1;
			
			foreach ($noticias_geral as $noticia) {
	
				if (strlen($noticia['Noticia']['text']) >= 150) {
					$abstract = substr($noticia['Noticia']['text'],0, 150)."...";
	
				}
				else {
					$abstract = $noticia['Noticia']['text'];
				}
	
				
				echo "<div style='margin-bottom:5px; margin-top:5x; width:100%;'>";
	
				// Botão "mais"
				echo html_entity_decode
				(
					$html->link
					(
						$html->image
						(
							'plus.jpg',
							array
							(
								'id'=>'plus'.$i,
								'class'=>'icon',
								'onclick'=>'javascript:troca(\'minus'.$i.'\',\'plus'.$i.'\')',
	
							)
						),
	
						'javascript:Effect.toggle(\'new'.$i.'\',\'appear\');',
						array
						(
							'class'=>'news_link'
						)
					)
				);
	
				// Botão "menos"	
				echo html_entity_decode
				(
					$html->link
					(
						$html->image
						(
							'minus.jpg',
							array
							(
								'id'=>'minus'.$i,
								'class'=>'icon',
								'style'=>'display:none;',
								'onclick'=>'javascript:troca(\'plus'.$i.'\',\'minus'.$i.'\')',
	
							)
						),
						'javascript:Effect.toggle(\'new'.$i.'\',\'appear\');',
						array
						(	
							'class'=>'news_link'
						)
					)
				);
	
				// Título da Notícia
				echo $html->link($noticia['Noticia']['title'], '/noticias/view/'.$noticia['Noticia']['id'], array('class'=>'news_link'));
				echo ' - <i style="color:gray"> ';
				echo date("d/m/Y",strtotime($noticia['Noticia']['created']));
				echo '</i> ';
				
				echo '</div>';				
				
	
				// Conteúdo da Notícia
				echo '<div id="new'.$i.'" style="display:none;margin-left:15px;margin-right:5px;">';
				echo "<span> ".$abstract."</span>";
				echo '</div>';	
				$i++;
			}			
			echo '</div>';

		echo $html->link('Ver todas','/noticias/',array('class'=>'boxLink'));	

		echo $box->finalizaBloco();
		}

	echo '</div>'; // finalizando coluna da esquerda


	// Coluna da Direita
	echo '<div style="width:365px;display:inline;float:left">';

		// Box de mensagens		
		if(isset($messages))
		{
		echo $box->iniciaBloco("Novas Mensagens");
			echo "<table style='border-width: 0px; border-style:none'>";
			/* Registros */
			$i=0;
			foreach ($messages as $message) {
	
				if ($message['Message']['read']==0) {
					if (strlen($message['Message']['text']) >= 20) {
						$abstract = substr($message['Message']['text'],0, 20)."...";
					}
					else {
						$abstract = $message['Message']['text'];
					}
		
					if (($i++ % 2) == 1)
						$zebrado = " class='oddTr' ";
					else
						$zebrado = "";
		
					echo "<tr ".$zebrado.">";
					echo "<td style='border-style:none'>";
		
					if ($message['Message']['read']==0) {
						echo $html->image('mail/mail_unread.png', array('class'=>'mail_home'));
					}
					else if (!empty($message['Replied'])) {
						echo $html->image('mail/mail_reply.png', array('class'=>'mail_home'));
					}
					else {
						echo $html->image('mail/mail_read.png', array('class'=>'mail_home'));
					}
		
					echo "</td>";
					echo "<td style='border-style:none'>" .$html->link($message['From']['name'],'/users/view/'.$message['From']['id'])." - ".
						$html->link($message['Message']['subject'],'/messages/view/'.$message['Message']['id'])." ".
						htmlspecialchars ($abstract)." 
					- <i style='color:gray'>".
					date("d/m/Y",strtotime($message['Message']['created'])).
					"</i> </td>";

					echo "</tr>";
				}
			}
			if($i ==0)
			{
				echo('Nenhuma mensagem nova.');	
			}
			echo "</table>";
	
			echo $html->link('Ver todas','/messages/',array('class'=>'boxLink'));
	
		echo $box->finalizaBloco();
		}
	
	echo '</div>';
	
	
	// Coluna da Direita - forums
	echo '<div style="width:365px;display:inline;float:left">';

		// Box de mensagens		
		if(isset($forums))
		{
		echo $box->iniciaBloco("Últimas postagens dos forums");
			echo "<table style='border-width: 0px; border-style:none'>";
			/* Registros */
			$i=0;
			echo "<ul id='forum_list'>";
			foreach ($forums as $forum) {
				echo "<li>";

				$link = Router::url("/forums/view/".$forum['Forum']['id']); 
				echo "<a class='link' href='".$link."'>".$forum['Forum']['title']."</a> em ".date("d/m/Y",strtotime($forum['Forum']['modified']));

				echo "</li>";
				$i++;
				 /*
				if ($message['Message']['read']==0) {
					if (strlen($message['Message']['text']) >= 20) {
						$abstract = substr($message['Message']['text'],0, 20)."...";
					}
					else {
						$abstract = $message['Message']['text'];
					}
		
					if (($i++ % 2) == 1)
						$zebrado = " class='oddTr' ";
					else
						$zebrado = "";
		
					echo "<tr ".$zebrado.">";
					echo "<td style='border-style:none'>";
		
					if ($message['Message']['read']==0) {
						echo $html->image('mail/mail_unread.png', array('class'=>'mail_home'));
					}
					else if (!empty($message['Replied'])) {
						echo $html->image('mail/mail_reply.png', array('class'=>'mail_home'));
					}
					else {
						echo $html->image('mail/mail_read.png', array('class'=>'mail_home'));
					}
		
					echo "</td>";
					echo "<td style='border-style:none'>" .$html->link($message['From']['name'],'/users/view/'.$message['From']['id'])." - ".
						$html->link($message['Message']['subject'],'/messages/view/'.$message['Message']['id'])." ".
						htmlspecialchars ($abstract)." 
					- <i style='color:gray'>".
					date("d/m/Y",strtotime($message['Message']['created'])).
					"</i> </td>";

					echo "</tr>";
				}*/
			}
			echo "</ul>";
			if($i ==0) {
				echo('Nenhuma postagem.');	
			}
			echo "</table>";
	
			echo $html->link('Ver todas','/forums/',array('class'=>'boxLink'));
	
			echo $box->finalizaBloco();
		}
	
	echo '</div>';
	
		




